package com.android.settings.ios.general;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;

import com.android.settings.ios.R;
import com.android.settings.ios.SettingsMainActivity;

public class GeneralEditSEIDFragment extends Fragment {

    private String mLastName = "";
    private SharedPreferences mPreferences;

    protected String mMainTitle;
    protected String mBackSubTitle;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mBackSubTitle = bundle.getString("fragment_back", null);
            mMainTitle = bundle.getString("fragment_title", getString(R.string.app_name));
        }

        mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
        mLastName = mPreferences.getString("about_seid_num", "04230F435327800141860174889311236F6125768123345C");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.os_general_edit_seid_fragment, null);
        TextView textView = view.findViewById(android.R.id.text1);
        if (textView != null) {
            textView.setText(mLastName);
        }
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        updateTitleIfNeeded();
    }

    protected void updateTitleIfNeeded() {
        Activity activity = getActivity();
        if (activity instanceof SettingsMainActivity) {
            activity.setTitle(mMainTitle);
            ((SettingsMainActivity) activity).setLeftBackText(mBackSubTitle);
        }
    }
}
